import { sendTxtMsg as netease_send_txtmsg } from './netease';
import {ajax_user} from './ajax';

export const SETCHATLOG = 'setchatlog';
export const UPDATECHATLOGCONTENT = 'upchatlogct';
export const APPENDCHATLOG = 'apchatlog';

export function sendTxtMsg(fuid, tuid, content, dispatch, cb){
    ajax_user("v1-1/im/chat_spend", {
        touid: tuid,
        cat: "words",
        msg: content
    })
    .then(responseJson => {
        if(responseJson.result == 1){
            dispatch({
                type: APPENDCHATLOG,
                uid: tuid,
                fuid: fuid,
                content: content,
                time: (new Date()).valueOf()
            });
            netease_send_txtmsg(fuid, tuid, content);
            cb();
        }
    })
}